#!/usr/bin/env node

const koa = require('koa'),
  bodyparser = require('koa-bodyparser'),
  // tasks = require('./routes/tasks.js'),
  admin = require('./routers/admin_router'),
  user = require('./routers/user_router'),
  business = require('./routers/business_router'),
  commodity = require('./routers/commodity_router'),
  dynamic = require('./routers/dynamic_router'),
  comment = require('./routers/comment_router'),
  collection = require('./routers/collection_router'),
  report = require('./routers/report_router'),
  feedback = require('./routers/feedback_router'),
  tim = require('./routers/tim_router.js'),
  koabody = require('koa-body'),
  county = require('./routers/county_router'),
  appointment = require('./routers/appointment_router'),
  json = require('koa-json'),
  logger = require('koa-logger'),
  cors = require('koa2-cors'),
  // jwt = require('koa-jwt'),
  // jwt2 = require('jsonwebtoken'),
  // {JWT_KEY} = require('./lib/constant.js'),
  express = require('express'),
  app = new koa({
    debug: true,
    http: true,
    key: '/usr/local/cert/www.h5weixin.club.key',
    cert: '/usr/local/cert/www.h5weixin.club.crt'
  });

app.use(json());
app.use(logger());
app.use(cors({
  "Access-Control-Allow-Origin": "*"
}));
app.use(koabody({
  multipart: true,
  strict: false
}));
//app.use(jwt({secret:JWT_KEY}).unless({
//	path:[/\/api\/user\/register$/,
//		/\/api\/user\/slg$/]}));
app.use(bodyparser({ enableTypes: ['json', 'form', 'text'] }));
//app.use(async(ctx,next)=>{
//   let token = ctx.header.authorization;
//   if(typeof token !== 'undefined'){
//     token = token.split(' ')[1];
//	console.log(token);
//     let user = jwt2.verify(token,JWT_KEY);
//     ctx.userId = user.id;
//   }

//   await next();
// });
app.use(admin.routes());
app.use(business.routes());
app.use(user.routes());
app.use(commodity.routes());
app.use(comment.routes());
app.use(dynamic.routes());
app.use(county.routes());
app.use(report.routes());
app.use(feedback.routes());
app.use(collection.routes());
app.use(appointment.routes());
app.use(tim.routes());
app.listen(1024);
